<?php
class Administrator_HomeController extends QSource_System_Controller_Action{
	public function init(){
		$this->loadTemplate('administrator');
	}
	public function indexAction(){ 
		$configHotNews = new Zend_Config_Ini(APPLICATION_PATH.'/blocks/default/HomeHotNews/config.ini', 'config');
		$dataHotNews = $configHotNews;
		$this->view->dataHotNews = $dataHotNews;
		$configCategory = new Zend_Config_Ini(APPLICATION_PATH.'/blocks/default/HomeCategory/config.ini', 'config');
		$dataCategory = $configCategory;
		$this->view->dataCategory = $dataCategory;
	}	
	public function configAction(){ 
	    $block = $this->_request->getParam('block','');
	    if($block=='')
	    	$this->_redirect('administrator/home');
	    if($this->_request->isPost())
	    {
	    	$data = $this->_request->getParams();
	    	if($block=='HomeHotNews')
		    {
		    	$item = array('config'=>array('feature'=>$data['feature'],'item1'=>$data['item1'],'item2'=>$data['item2'],'item3'=>$data['item3']));
			    $config = new Zend_Config_Writer_Ini();
			    $config->write(APPLICATION_PATH.'/blocks/default/HomeHotNews/config.ini',new Zend_Config($item));
		    }
	   		if($block=='HomeCategory')
		    {
		    	$item = array('config'=>array('category1'=>$data['category1'],'category2'=>$data['category2'],'category3'=>$data['category3'],'category4'=>$data['category4'],'category5'=>$data['category5']));
			    $config = new Zend_Config_Writer_Ini();
			    $config->write(APPLICATION_PATH.'/blocks/default/HomeCategory/config.ini',new Zend_Config($item));
		    }
		    $this->_redirect('administrator/home');
	    }
	    else
	    {
		    if($block=='HomeHotNews')
		    {
		    	$configHotNews = new Zend_Config_Ini(APPLICATION_PATH.'/blocks/default/HomeHotNews/config.ini', 'config');
				$data = $configHotNews;
				$this->view->data = $data;
		    }
	    	if($block=='HomeCategory')
		    {
		    	$configCategory = new Zend_Config_Ini(APPLICATION_PATH.'/blocks/default/HomeCategory/config.ini', 'config');
				$data = $configCategory;
				$this->view->data = $data;
		    }
		    $this->view->name = $block;
	    }
	}
	public function advancedAction(){ 
	    $id = 1;
	    $model = new Model_SiteInfo_SiteInfo();
	    if($this->_request->isPost())
	    {
	    	$error = array();
	    	//Lấy thông tin của form post
	    	$data = $this->_request->getParams();
	    	if (count($error) > 0) {
	    		$this->view->error = $error;
	    		$this->view->data = $data;
	    	} else {
	    		$item = array('google_webmaster'=>$data['google_webmaster'],'google_analytics'=>$data['google_analytics'],'offline'=>$data['offline']);
	    		$model->update($item,'id = '.$id);
	    		$this->view->success = 'Đã thêm thể loại mới thành công';
	    		$this->_redirect('administrator/configuration');
	    	}
	    
	    }
	    else
	    {
	    	$data = $model->getItemId($id);
	    	$this->view->data = $data;
	    }
	}
}